﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;
using System.Reflection;


namespace Zealib.Extensions
{
    /// <summary>
    /// Extensions for <see cref="System.Reflection"/> namespace.
    /// </summary>
    public static class ReflectionExtender
    {
        public static T GetAttribute<T>(this Assembly self) where T : Attribute
        {
            self.IsNotNull();
            return Attribute.GetCustomAttribute(self, typeof(T)) as T;
        }

        public static T GetAttribute<T>(this MemberInfo self) where T : Attribute
        {
            self.IsNotNull();
            return Attribute.GetCustomAttribute(self, typeof(T)) as T;
        }

        public static T GetAttribute<T>(this MemberInfo self, bool inherit) where T : Attribute
        {
            self.IsNotNull();
            return Attribute.GetCustomAttribute(self, typeof(T), inherit) as T;
        }

        public static T GetAttribute<T>(this Module self) where T : Attribute
        {
            self.IsNotNull();
            return Attribute.GetCustomAttribute(self, typeof(T)) as T;
        }

        public static T GetAttribute<T>(this ParameterInfo self) where T : Attribute
        {
            self.IsNotNull();
            return Attribute.GetCustomAttribute(self, typeof(T)) as T;
        }
    }
}
